package com.mq;

import com.entity.BaoxiaoEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

@Component
public class PayslipConsumer {


    @Autowired
    private JavaMailSender javaMailSender;

    @JmsListener(destination = "payslip")
    public void receiveMsg(BaoxiaoEntity baoxiaoEntity){

        try {
            MimeMessage mimeMessage = javaMailSender.createMimeMessage();
            MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true);
            helper.setFrom("1842452729@qq.com");
            helper.setTo(baoxiaoEntity.getMailAddr());
            helper.setSubject("工资条明细");
            helper.setText("您好，如下是您本月发放工资条，如有问题，请及时联系部门助理。",true);
            javaMailSender.send(mimeMessage);

        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }
}
